package com.gopay.checkorder.service.task.thread;

import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.CountDownLatch;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.gopay.checkorder.service.AdPayAuthOrderService;
import com.gopay.common.constants.bank.BankOrderStatus;
import com.gopay.common.domain.bank.BankAuthOrder;

/**
 * 鉴权查询多线程实现
 * 
 * @AdpayAuthCheckOrderTaskThread.java
 * @author lilili
 * @2017-1-17 上午11:53:31 www.gopay.com.cn Inc.All rights reserved.
 */

public class AdpayAuthCheckOrderTaskThread implements Runnable {

	private final static Logger logger = LoggerFactory.getLogger("CHECK_ORDER");

	private ConcurrentLinkedQueue<BankAuthOrder> queue;
	private CountDownLatch latch;
	@Resource(name = "adPayAuthOrderService")
	private AdPayAuthOrderService adPayAuthOrderService;

	public AdpayAuthCheckOrderTaskThread(){
		
	}
	
	public AdpayAuthCheckOrderTaskThread(AdPayAuthOrderService adPayAuthOrderService, ConcurrentLinkedQueue<BankAuthOrder> queue, CountDownLatch latch) {
		this.queue = queue;
		this.latch = latch;
		this.adPayAuthOrderService = adPayAuthOrderService;
	}

	@Override
	public void run() {
		BankAuthOrder bankOrder = queue.poll();
		if (bankOrder != null) {
			// 对单
			adPayAuthOrderService.checkOrder(bankOrder, BankOrderStatus.AUTO_CHECK_SUCCESS);
			logger.info("**********************当前队列剩余订单数：" + queue.size());
		}

		latch.countDown();
	}

	public void setQueue(ConcurrentLinkedQueue<BankAuthOrder> queue) {
		this.queue = queue;
	}

	public void setLatch(CountDownLatch latch) {
		this.latch = latch;
	}

	public void setAdPayAuthOrderService(AdPayAuthOrderService adPayAuthOrderService) {
		this.adPayAuthOrderService = adPayAuthOrderService;
	}

}
